package com.polaris.live.adapter.party

import android.annotation.SuppressLint
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.polaris.live.R.color
import com.polaris.live.adapter.party.ModifyPriceAdapter.ModifyPriceHolder
import com.polaris.live.databinding.AdapterModifyPriceBinding

/**
 * ModifyPriceAdapter
 *
 * @author Created by 天晴 on 2024/3/19 16:30
 * @since 1.0.0
 **/
class ModifyPriceAdapter : BaseQuickAdapter<Long, ModifyPriceHolder>(0) {

    private var lastPosition = 0

    @SuppressLint("NotifyDataSetChanged")
    fun setClickPosition(position: Int) {
        lastPosition = position
        notifyDataSetChanged()
    }

    override fun onCreateDefViewHolder(
        parent: ViewGroup,
        viewType: Int
    ): ModifyPriceHolder {
        return ModifyPriceHolder(
            AdapterModifyPriceBinding.inflate(
                LayoutInflater.from(parent.context),
                parent,
                false
            )
        )
    }

    override fun convert(holder: ModifyPriceHolder, item: Long) {
        val position = holder.layoutPosition
        holder.binding.nameTv.apply {
            text = data[position].toString()
            if (position == lastPosition) {
                setTextColor(ContextCompat.getColor(context, color.fe194c))
                setBackgroundResource(com.polaris.live.R.drawable.r8_back_fe194c_tok)
            } else {
                setTextColor(ContextCompat.getColor(context, color.b3b3b3))
                setBackgroundResource(com.polaris.live.R.drawable.r8_back_f8f8f8_tok)
            }
        }
    }

    inner class ModifyPriceHolder(val binding: AdapterModifyPriceBinding) :
        BaseViewHolder(binding.root) {

    }
}